import java.util.Scanner;

public class Main2_2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        in.nextLine();
        String[] arr = new String[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextLine();
        }
        int k = in.nextInt();
        in.nextLine();
        for (int i = 0; i < k; i++) {
            String s = in.nextLine();
            String[] arr2 = s.split(" ");
            char[] first = new char[arr2.length];
            for (int j = 0; j < arr2.length; j++) {
                first[j] = arr2[j].charAt(0);
            }
            int index = 0;
            for (int j = 0; j < n; j++) {
                String[] old = arr[i].split(" ");
                boolean flag = true;
                for (int l = 0; l < first.length; l++) {
                    if(first[l] != old[l].charAt(0)) {
                        flag = false;
                    }
                }
                if(old.length != first.length && flag) {
                    continue;
                }
                

            }
        }
    }
}
